package com.sample.springbatch.scheduler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 通过Scheduled注解实习定时任务调度
 *
 * @author zwg
 * @date 2019-05-06 17:26
 **/
@Component
public class ScheduledService {

    Logger logger = LoggerFactory.getLogger(ScheduledService.class);
    /**
     * 每分钟执行一次，支持完成才会执行下一次。
     */
    //@Scheduled(cron = "*/5 * * * * *")
    public void run(){
        Long id = System.currentTimeMillis();
        logger.info("run begin:{}",id);
        if(id%10==1){
            throw new RuntimeException("self throw execption");
        }
        try{
            Thread.sleep(10000L);
        }catch (Exception e){

        }
        logger.info("run end:{}",id);

    }
}
